import requests
import time
import execjs
import re
import json

headers = {
    'Host': 'sso.kongzhong.com',
    'Referer': 'https://passport.kongzhong.com/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36'
}


url = 'https://sso.kongzhong.com/ajaxLogin?'

session = requests.Session()
res = session.get(url="https://sso.kongzhong.com/ajaxLogin?j=j&jsonp=j&service=https://passport.kongzhong.com/&_=%s"%time.time(), headers=headers).text

pattern="KZLoginHandler.jsonpCallbackKongZ\((.*)\)"
result=re.findall(pattern,res)[0]
dc=json.loads(result)["dc"]
print("dc:%s"%dc)
node=execjs.get()
ctx=node.compile(open("天空网.js",encoding="utf-8").read())
p='a123456789A_'
funcname="getpwd('%s','%s')"%(p,dc)
password=ctx.eval(funcname)
print("password:%s" % password)


cap = session.get(url='https://sso.kongzhong.com/createVCode?', headers=headers)
with open('cap.jpg', 'wb') as f:
    f.write(cap.content)

vcode = input('请输入验证码:')
param_data = {
    'j': 'j',
    'type': 1,
    'service': 'https://passport.kongzhong.com/',
    'username': '18888888888',
    'password': password,
    'vcode': vcode,
    'toSave': 0,
    '_': time.time()
}

res1 = session.get(url='https://sso.kongzhong.com/ajaxLogin?', params=param_data, headers=headers)
print(res1.status_code)
print(res1.text)
